home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7178 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C constant expression declarations
  5. Date: 16 Feb 96 11:40:44 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824470844@rscernix>
  8. References: <31229735.41C67EA6@isi.com> <DMto56.Lo3@uns.bris.ac.uk> <4fvm2hINNa61@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4fvm2hINNa61@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  13.  
  14. >In article <DMto56.Lo3@uns.bris.ac.uk>,
  15. >Nathan Sidwell <nathan@pact.srf.ac.uk> wrote:
  16. > >: ...and so on.  Lately, I have been observing in code from other people
  17. > >: equivalent declarations such as:
  18. > >
  19. > >:  #define EXPR1   (1)
  20. > >:  #define EXPR2   (2)
  21. > >
  22. > >Whilst, as I'm sure you realise, it's necessary to put brackets round
  23. > >things like (a + b), it is not necessary around unsigned constants.
  24. > >However, a gotcha is using signed constants, for example
  25. > >
  26. > >#define    EXPR -1
  27. > >if(a EXPR) ...
  28. >
  29. >Are you sure that C has signed constants? That is, is -1 lexically recognized
  30. >as a constant, or as a minus token followed by an integer quantity? It's
  31. >probably done the latter way, which means that "-1" is a compound expression.
  32. >If it weren't parsed this way, a construct like (a-1) would be parsed as
  33. >something like '(' IDENTIFIER INTEGER ')', a syntax error. I'm not sure what th
  34. >C standard says, just what common-sense about compiler construction says. :)
  35. >
  36. > >this will complile as 'a - 1', rather than give a syntax error
  37.  
  38. This single line makes Kazimir's paragraph above completely pointless.
  39. Do people actually read the text they're commenting on?
  40.  
  41. It's obvious (in context) that Nathan's "signed constants" was an
  42. unfortunate expression and he doesn't believe that C has signed constants.
  43.  
  44. Dan
  45. --
  46. Dan Pop
  47. CERN, CN Division
  48. Email: danpop@mail.cern.ch 
  49. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  50.